//
//  NSMutableString+BZSafe.h
//  BZFoundation
//
//  Created by 郭艺伟 on 2017/10/1.
//  Copyright © 2017年 郭艺伟. All rights reserved.
//

#import <Foundation/Foundation.h>
#ifndef BZStringAppendString
#define BZStringAppendString(string,aString)                         \
if ((aString)) {                                               \
[(string) appendString:(aString)];                          \
}
#endif

#ifndef BZStringInsertStringAtIndex
#define BZStringInsertStringAtIndex(string,aString,index)                         \
if ((aString) && (index)<=[(string) length] && (index) >= 0) {                  \
[(string) insertString:(aString) atIndex:(index)];                          \
}
#endif

#ifndef BZStringSetString
#define BZStringSetString(string,aString)                         \
if ((aString)) {                                               \
[(string) setString:(aString)];                          \
}
#endif

#ifndef BZStringReplaceCharactersInRangeWithString
#define BZStringReplaceCharactersInRangeWithString(string,range,aString)                         \
if ((aString) && (range).location >= 0 && (range).length > 0 && (range).location < [(string) length] && NSMaxRange(range)<=[(string) length]) {                  \
[(string) replaceCharactersInRange:(range) withString:(aString)];                          \
}
#endif

#ifndef BZStringDeleteCharactersInRange
#define BZStringDeleteCharactersInRange(string,range)                         \
if (((range).location) >= 0 && (range).length > 0 && (range).location < [(string) length] && NSMaxRange(range)<=[(string) length]) {                  \
[(string) deleteCharactersInRange:(range)];                          \
}
#endif

#ifndef BZStringSubStringWithRange
#define BZStringSubStringWithRange(string,range,subString)                         \
if (((range).location) >= 0 && (range).length > 0  && (range).location <= [(string) length] && NSMaxRange(range)<=[(string) length]) {                  \
(subString) = [(string) substringWithRange:(range)];                          \
} else { \
(subString) = nil;\
}
#endif

#ifndef BZStringSubStringFromIndex
#define BZStringSubStringFromIndex(string,index,subString)                         \
if ((index)<[(string) length] && (index) >= 0) {                  \
(subString) = [(string) substringFromIndex:(index)];                          \
} else { \
(subString) = nil;\
}
#endif

#ifndef BZStringSubStringToIndex
#define BZStringSubStringToIndex(string,index,subString)                         \
if ((index)<=[(string) length] && (index) >= 0) {                  \
(subString) = [(string) substringToIndex:(index)];                          \
} else { \
(subString) = nil;\
}
#endif
@interface NSMutableString (BZSafe)

@end
